﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace Gui.Functies.Takenlijst_popups
{
    public partial class Addlid : Form
    {
        int naamid;
        int projectID;
        static int counter = 0;
        int[] userid = new int[20];

        public Addlid()
        {

        }

        public Addlid(int projectnummer)
        {
            projectID = projectnummer;
            InitializeComponent();
            getMember();
            //getTaken();
        }


        public void getMember()
        {
            try
            {
                projectID = 37;
                MySqlConnection grabConnection = new MySqlConnection("Server=qq-design.com;Port=3306;Database=cookicom0;Uid=cookicom0;pwd=pizzahut91");
                MySqlCommand memberGet = new MySqlCommand("SELECT UserID FROM project_members WHERE ProjectID='" + projectID + "'", grabConnection);

                grabConnection.Open();

                MySqlDataReader reader = memberGet.ExecuteReader();

                if (reader.Read() != false)
                {
                    if (reader.IsDBNull(0) == true)
                    {
                        grabConnection.Close();
                        reader.Dispose();
                        memberGet.Dispose();
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            userid[counter] = reader.GetInt32(0);
                            //naamid = reader.GetInt32(0);
                            Console.WriteLine(userid[counter]);
                            counter++;

                        }

                        reader.Close();
                    }
                    getName(userid);
                    grabConnection.Close();
                    reader.Dispose();
                    memberGet.Dispose();
                }
            }

            catch (MySqlException e)
            {
                Console.Write(e);
                MessageBox.Show("Sql error detected!");
            }
        }


        public void getName(int[] userid)
        {
            int[] ids = userid;

            try
            {
                MySqlConnection grabConnection2 = new MySqlConnection("Server=qq-design.com;Port=3306;Database=cookicom0;Uid=cookicom0;pwd=pizzahut91");
                 grabConnection2.Open();
                 for (int i = 0; i <= userid.Length; i++)
                 {
                    // if (userid[i] == null)
                     //{
                      //   break;
                     //}
                     MySqlCommand memberGet2 = new MySqlCommand("SELECT Naam FROM confirmed_users WHERE UserID='" + userid[i] + "'", grabConnection2);
                     MySqlDataReader reader2 = memberGet2.ExecuteReader();


                     if (reader2.Read() != false)
                     {
                         if (reader2.IsDBNull(0) == true)
                         {
                             grabConnection2.Close();
                             reader2.Dispose();
                             memberGet2.Dispose();
                         }
                         else
                         {
                             while (reader2.Read())
                             {

                                 comboBox1.Items.Add(reader2["Naam"]);
                             }

                             reader2.Close();
                         }

                        grabConnection2.Close();
                         reader2.Dispose();
                         memberGet2.Dispose();
                     }
                 }
            }
            catch (MySqlException e)
            {
                Console.Write(e);
                MessageBox.Show("Sql error detected!");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //naam = comboBox1.SelectedItem.ToString(); // moet de lijst met leden worden die in het project zitten, + lidID is nodig

            //taak = comboBox2.SelectedItem.ToString(); // lijst met taken, taakID moet meegegeven worden
        }
        /*/ if (naam != "" && taak != "")
         {
             addMember();
         }
         else
         {
             MessageBox.Show("Niet alle velden zijn ingevuld!");
         }
     }/*/



        private void Addlid_Load(object sender, EventArgs e)
        {

        }
    }
}

